package com.mybatis.moudles.test;

import okhttp3.*;

import java.io.IOException;

public class OKHttpDemo {
      //发送get请求
/*    public static  void main(String[] args) throws IOException {
        String url="http://test.lemonban.com/ningmengban/app/login/login.html";
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder().url(url).get().build();
        Response response =client.newCall(request).execute();
        System.out.println(response.code());
        System.out.println(response.headers());
        System.out.println(response.body().string());
    }*/

    //发送post请求
    public static void main(String[] args) throws IOException {
       String url="http://test.lemonban.com/ningmengban/app/login/login.html";
        OkHttpClient client = new OkHttpClient();
        MediaType type = MediaType.parse("application/x-www-form-urlencoded");
        RequestBody body =RequestBody.create(type,"username=181222&password=fandanping521");
        Request request = new Request.Builder().url(url).post(body).build();
        Response response =client.newCall(request).execute();
        System.out.println(response.code());
        System.out.println(response.headers());
        System.out.println(response.body().string());

    }

}
